https://leetcode.cn/problems/sliding-window-maximum/description/



class Solution {
public:
    vector<int> maxSlidingWindow(vector<int>& nums, int k) {
        if(nums.empty()||nums.size()<k) return {};
        std::deque<int> q;
        size_t i=0;
        std::vector<int> res;
        for(;i<k;++i){
            if(q.empty()){
                q.emplace_back(i);
            }else{
                while(!q.empty()&&nums[q.back()]<nums[i]){
                    q.pop_back();
                }
                q.emplace_back(i);
            }
        }
        res.push_back(nums[q.front()]);
        for(;i<nums.size();++i){
            if(i-q.front()==k){
                q.pop_front();
            }
            while(!q.empty()&&nums[q.back()]<nums[i]){
                    q.pop_back();
            }
            q.emplace_back(i);
            res.push_back(nums[q.front()]);
        }
        return res;
    }
};